require ['knockout', 'adFloat','jquery','bootstrap'], (ko, adFloat, $) ->
  ko.components.register 'ad-float', adFloat
  class viewModel
    constructor: ->
    ajaxLi:ko.observableArray()
    clickajax: (id,title)->
      $('.modal-title').html(title)
      Promise.resolve $.ajax
        type: 'post'
        url: './corpcourseCommentList'
        data:
          'courseId': id
          'pageSize': 1000
          'pageIndex': 1
      .then (data)=>
        @ajaxLi(data.data.data.comments.items)
        $("#ajaxLi li").show()
      return
    clickHideOthers: (id)->
      $("#ajaxLi li").hide()
      $("#ajaxLi li[userid='"+id+"']").show()
      return
    clickShowOthers: ->
      $("#ajaxLi li").show()
      return
  ko.applyBindings new viewModel()
  $ ->
    $('.tab .text').click ->
      t1 = $('.tab1')
      t2 = $('.tab2')
      i = $(this).index() + 1
      $('.tabC').removeClass 'active'
      show = if i == 1 then t1 else t2
      show.addClass 'active'
      $('.tab .text').removeClass 'active'
      $(this).addClass 'active'
      return
    $('.select_1').click ->
      $(this).find('.option').toggle()
      return
    for i in $('.center_list td[time]')
      t = $(i).attr('time')
      hour = parseInt(t/3600)
      min = parseInt((t-hour*3600)/60)
      sec = parseInt(t-hour*3600-min*60)
      $(i).html(hour+'时'+min+'分'+sec+'秒')
    at = $('#addTime')
    att = at.attr('time')
    hour = parseInt(att/3600)
    min = parseInt((att-hour*3600)/60)
    sec = parseInt(att-hour*3600-min*60)
    at.html('已学习<span>'+hour+'</span>时<span>'+min+'</span>分<span>'+sec+'</span>秒')
    commentVideoLi = $('#commentVideo li')
    commentVideoLiLoopNum = commentVideoLi.length
    corpcourseCommentList = new Array()
    commentVideoLiNum = () ->
      n = corpcourseCommentList.length - 1
      data = corpcourseCommentList[n].data
      if not data.status
        console.log '第'+(n+1)+'元素'+data.msg
        $(commentVideoLi[n]).find('.watch').find('span').html('0条分享')
      else
        items = data.data.comments.items
        viewsNum = data.data.comments.total
        console.log data.data.comments
        if viewsNum<= 50
          num = 1
        else if viewsNum>50 && viewsNum<=100
          num = 2
        else if viewsNum>100 && viewsNum<=300
          num = 3
        else if viewsNum>300 && viewsNum<=500
          num = 4
        else
          num = 5
        b = 0
        while b<num
          $(commentVideoLi[n]).find('.grade').find('i').eq(b).addClass('active')
          b++
        if not items
          $(commentVideoLi[n]).find('.watch').find('span').html('0条分享')
        else
          $(commentVideoLi[n]).find('.watch').find('span').html(viewsNum+'条分享')
      if i<commentVideoLiLoopNum-1
        commentVideoLiNumloop(++i)
      return
    i = 0
    commentVideoLiNumloop = (i)->
      if !commentVideoLiLoopNum
        return
      id = $(commentVideoLi[i]).attr('courseId')
      Promise.resolve $.ajax
        type: 'post'
        url: './corpcourseCommentList'
        data:
          'courseId': id
          'pageSize': 1000
          'pageIndex': 1
      .then (data)=>
        corpcourseCommentList.push data
        commentVideoLiNum()
      return
    commentVideoLiNumloop(i)






